/* eslint-disable */
import React, { Component } from 'react';

import { message } from 'antd';

import API from '../../../api/account/index';

import './Share.scss'

import Sidebar from '../Sidebar/Sidebar'
import Main from '../Main/Main'
import WebBind from '../WebBind/WebBind'
import Popup from '../../components/Popup/Popup';

class Share extends Component {
  state = {
    account: null,
    popupVisible: false,
    wechatBindVisible: false,
  }
  componentDidMount () {
    // this.checkWechatBound();
    this.getUser();
  }
  // fetch user's info if login succeed
  getUser = async () => {
    const response = await API.getUserInfo();
    const { code, data } = response;
    if (code === 1) {
      !(data.company) && (data.company = {})
      !(data.tel) && (data.tel = {})
      !(data.wechat) && (data.wechat = {})
      !(data.department) && (data.department = [])
      // put user's info intou sessionStorage
      window.sessionStorage.setItem('account', JSON.stringify(data));
      this.setState({
        account: data
      })
    }
  }
  checkWechatBound = async () => {
    const response = await checkWechatBound()
    console.log('checkWechatBound', response)
    const { code, data } = response
    if (code === 1) {
      if (!data) {
        this.setState({
          popupVisible: true,
          wechatBindVisible: true,
        })
      }
    } else {
      console.error('微信绑定接口获取失败！')
    }
  }
  render () {
    const { account } = this.state;
    return (
      <div style={{ width: '100%', height: '100%' }}>
        {
          account !== null ? (
            <div className="share-view">
              <Sidebar />
              <Main />
              <Popup visible={this.state.popupVisible} wechatBindVisible={this.state.wechatBindVisible} />
            </div>
          ) : null
        }
      </div>
    );
  }
}

export default Share;
